package com.elric.mall.controller;

import com.elric.mall.common.api.CommonResult;
import com.elric.mall.dto.CodeGenerateParam;
import com.elric.mall.dto.XnCodeGenParam;
import com.elric.mall.service.CodeGenerateService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 代码生成器
 */
@Controller
@Api(tags = "CodeGenerateController", description = "代码生成器")
@RequestMapping("/codeGenerate")
public class CodeGenerateController {

    @Autowired
    private CodeGenerateService codeGenerateService;

    /**
     * 查询当前数据库用户下的所有表
     */
    @GetMapping("/informationList")
    @ResponseBody
    public CommonResult informationList() {
        return CommonResult.success(codeGenerateService.informationTableList());
    }

    /**
     * 查询表对应的字段信息
     */
    @GetMapping("/columnsList")
    @ResponseBody
    public CommonResult columnsList(@RequestParam(value = "tableName", required = true) String tableName) {
        return CommonResult.success(codeGenerateService.selectInformationColumns(tableName));
    }


    /**
     * 代码生成基础配置生成
     *
     * @auther yubaoshan
     * @date 12/15/20 11:20 PM
     */
    @RequestMapping(value = "/runDown", method = RequestMethod.POST)
    public void runDown(@RequestBody XnCodeGenParam xnCodeGenParam, HttpServletResponse response) {
        codeGenerateService.runDown(xnCodeGenParam, response);
    }
}
